package com.wf.DouDiZhuOL;

import com.google.protobuf.InvalidProtocolBufferException;
import com.wf.DouDiZhuOL.Tools.Tools;
import com.wf.DouDiZhuOL.proto.GameModule.PBLogonRegist;
import com.wf.DouDiZhuOL.util.Constants;

import io.netty.channel.ChannelHandlerContext;

public class Router {
	private static Router _instance = null;
	
	public static Router getInstance() 
	{
		if(_instance == null) 
		{
			_instance = new Router();
		}
		return _instance;
	}
	
	public void route(int _type, String _data, ChannelHandlerContext _ctx) 
	{
		switch (_type) 
		{
		case Constants.REQ_TYPE_LOGON:
			this.logon(_data, _ctx);
			break;
		case Constants.REQ_TYPE_REGIST:
			
			break;
		default:
			break;
		}
	}
	
	private void logon(String _data, ChannelHandlerContext _ctx) 
	{
		if(_data == null || _data.equals("")) 
		{
			return;
		}
		
		byte[] dataBytes = Tools.strToByteArray(_data);
		try {
			PBLogonRegist logonRegist = PBLogonRegist.parseFrom(dataBytes);
			
			Tools.writeToastMsg(_ctx, Constants.TOAST_MSG_NORMAL, "登录成功！");
		} catch (InvalidProtocolBufferException e) 
		{
			e.printStackTrace();
		}
	}
}
